	$(function() {
		//数据加载
		//loadData("","",currentPage);  //全部
		nextState = "0";
	});

	var baseUrl = "/apistore/";
	//当前显示第几页
	var currentPage=1;
	//一共多少页数据
	var totalPage;

	var nextState = "";
	//产品认证状态条件删选
	$(document).on("click",".main_content_middle_menu_state",function(e){
		var stste = $(this).attr("stste");
		if(nextState!=""&&nextState!=null){
			$(".main_content_middle_menu_state[stste="+nextState+"]").removeClass("main_state_active");  //取消上次选中样式
			$(this).addClass("main_state_active");  //添加选中样式
		}else{
			$(this).addClass("main_state_active");  //添加选中样式
		}
		loadData(stste,"",currentPage);
		nextState = stste;
	});

	//认证状态统计
	function loadStateCountData(){
		var url = baseUrl+'recordController/selectByServerRecordStateCount';
		$.ajax({
			url : url,
			type : 'POST',
			ontentType:'application/json;charset=UTF-8',
			dataType: "JSON",
			success : function(data) {
				if (data != null) {
					$("#wrz").html(data.stateOne);
					$("#rzz").html(data.stateTow);
					$("#yrz").html(data.stateThree);
				}
			},
			error : function(error) {
				alert("认证状态获取失败！");
			}
		});
	}


	//数据加载
	function loadData(stste,serviceName,pageNum){
		//loadStateCountData();   //认证状态统计
		if(stste=="0"){  //状态为0的时候是查全部
			stste="";
		}
		var data = {
			currentPage : pageNum,
			pageSize : 3,
			ready01 : stste,		//认证状态
			ready02 : serviceName	//产品名称
		};
		var url = baseUrl+'recordController/selectByServerRecordPageList';
		$.ajax({
			url : url,
			data : data,
			type : 'POST',
			ontentType:'application/json;charset=UTF-8',
			dataType: "JSON",
			success : function(data) {
				var dataLists = null;
				if (data != null) {
					dataLists = data.dataList;
					var str="";
					if (dataLists == null) {
						$("#page").text("");
						str += "<div class=\"context_item\">";
						str += "<div class=\"notdata\">暂无数据</div>";
						str += "</div>";
					} else {
						//当前第几页
						currentPage = data.currentPage;
						//一共多少页数据
						totalPage = data.totalPage;
						var colorState = "statr_blue";
						for (var i = 0; i < dataLists.length; i++) {
							str += "<div class=\"main_content_middle_content_table_content\">";
							str += "<div class=\"main_content_middle_content_table_content_appkey\">";
							str += "APPKEY：" + isNull(dataLists[i].apikey) + "";
							str += "</div>";
							str += "<div class=\"main_content_middle_content_table_content_val\">";
							str += "<div class=\"main_content_middle_content_table_content_val_field\" title=\"" + isNull(dataLists[i].serviceName) + "\">" + isLengs(dataLists[i].serviceName) + "</div>";
							colorState = readColorState(dataLists[i].approvalState); //根据状态分配不同的显示颜色
							str += "<div class=\"main_content_middle_content_table_content_val_field " + colorState + "\">" + stateTransformation(dataLists[i].approvalState) + "</div>";
							str += "<div class=\"main_content_middle_content_table_content_val_field\">" + isNull(dataLists[i].applyTime) + "</div>";
							str += "<div class=\"main_content_middle_content_table_content_val_field\">" + isNull(dataLists[i].surplusDays) + "</div>";
							str += "<div class=\"main_content_middle_content_table_content_val_field_djzcsq statr_blue cursor\" serviceCode=\"" + isNull(dataLists[i].serviceCode) + "\" categoryCode=\"" + isNull(dataLists[i].categoryCode) + "\">点击再次申请</div>";
							str += "<div class=\"main_content_middle_content_table_content_val_field\">";
							str += "<div class=\"main_content_middle_content_table_content_val_field_operation\"><i class=\"fa fa-info-circle\" serviceCode=\"" + isNull(dataLists[i].serviceCode) + "\">&nbsp;详情</i></div>";
							//str+="<div class=\"main_content_middle_content_table_content_val_field_operation\"><i class=\"fa fa-signal\">&nbsp;统计</i></div>";
							str += "<div class=\"main_content_middle_content_table_content_val_field_operation\"><i class=\"fa fa-cogs\" serviceCode=\"" + isNull(dataLists[i].serviceCode) + "\">&nbsp;测试</i></div>";
							if (dataLists[i].surplusDays <= 10&&dataLists[i].surplusDays!=null&&dataLists[i].surplusDays!="") {
								str += "<div class=\"main_content_middle_content_table_content_val_field_operation\"><i class=\"fa fa-exclamation-circle fa-exclamation-circle-jinggao\" data-title=\"剩余" + isNull(dataLists[i].surplusDays) + "天！\">&nbsp;预警</i></div>";
							} else {
								str += "<div class=\"main_content_middle_content_table_content_val_field_operation\"><i class=\"fa fa-exclamation-circle\">&nbsp;预警</i></div>";
							}
							str += "</div>";
							str += "</div>";
							str += "</div>";
						}
						//构建分页信息
						loadPage(data);
					}
					$("#applylist").html(str);
				}
			},
			error : function(error) {
				alert("获取api列表失败！");
			}
		});
	}

	//构建分页信息
	function loadPage(data) {
		$("#page").text("");
		var pageStr = "";
		var pageNum = 0;
		pageStr += "<div class=\"main_content_middle_list_page_div\">";
		pageStr += "<div class=\"main_content_middle_list_page_div_yeshu\" id=\"prePage\">&lt;上一页</div>";
		var startindex = currentPage;  //当前页数
		var endindex = totalPage;  //总页数
		var spacenumb = endindex - startindex;
		if (spacenumb > 5) {
			endindex = startindex + 4;
		} else {
			if (totalPage > 5) {
				startindex = totalPage - 4;
			} else {
				startindex = 1;
			}
		}
		for (var i = startindex; i <= endindex; i++) {
			if (currentPage === i) {  //active默认选中样式
				pageStr += "<div class=\"main_content_middle_list_page_div_number pageactive\" onclick=\"pageNum('" + i + "')\">" + i + "</div>"
			} else {
				pageStr += "<div class=\"main_content_middle_list_page_div_number\" onclick=\"pageNum('" + i + "')\">" + i + "</div>"
			}
		}
			pageStr += "<div class=\"main_content_middle_list_page_div_yeshu\" id=\"nextPage\">下一页&gt;</div>";
			pageStr += "</div>";
			//"合计"+data.totalPage+" 页"
			//"共 "+data.totalRecord+"  条记录
			$("#page").append(pageStr);
	}

	//上一页
	$(document).on("click","#prePage",function(){
		priviousPage();
	});

	//下一页
	$(document).on("click","#nextPage",function(){
		nextPage();
	});

	//下一页
	function nextPage(){
		if(currentPage==totalPage){
			alert("已经是最后一页数据!");
			return false;
		}else{
			var stste= "";
			if($(".main_content_middle_menu_state").is(".main_state_active")){ 		//加载列表之前产品状态有没有被选中
				stste = $(".main_content_middle_menu_state.main_state_active").attr("stste") 	//查找有没有active的样式，有就拿到它的值
			}else{
				stste = "";	//没有就是空值
			}
			var serviceName = $("#serviceName").val();
			loadData(stste,serviceName,currentPage+1);
			return true;
		}
	};

	//当前页数加载
	function pageNum(pageNum){
		var stste= "";
		if($(".main_content_middle_menu_state").is(".main_state_active")){ 		//加载列表之前产品状态有没有被选中
			stste = $(".main_content_middle_menu_state.main_state_active").attr("stste") 	//查找有没有active的样式，有就拿到它的值
		}else{
			stste = "";	//没有就是空值
		}
		var serviceName = $("#serviceName").val();
		loadData(stste,serviceName,pageNum);
	}

	//上一页
	function priviousPage(){
		if(currentPage==1){
			alert("已经是第一页数据!");
			return false;
		}else{
			var stste= "";
			if($(".main_content_middle_menu_state").is(".main_state_active")){ 		//加载列表之前产品状态有没有被选中
				stste = $(".main_content_middle_menu_state.main_state_active").attr("stste") 	//查找有没有active的样式，有就拿到它的值
			}else{
				stste = "";	//没有就是空值
			}
			var serviceName = $("#serviceName").val();
			loadData(stste,serviceName,currentPage-1);
			return true;
		}
	}

	//判断为数据库null
	function isNull(reason){
		if(reason!=null&&reason!=""&&reason!="null"){
			return reason;
		}else{
			return "";
		}
	}

	//搜索按钮
	$(document).on("click","#search",function(){
		var stste= "";
		if($(".main_content_middle_menu_state").is(".main_state_active")){ 		//加载列表之前产品状态有没有被选中
			stste = $(".main_content_middle_menu_state.main_state_active").attr("stste") 	//查找有没有active的样式，有就拿到它的值
		}else{
			stste = "";	//没有就是空值
		}
		var serviceName = $("#serviceName").val();
		loadData(stste,serviceName,currentPage);
	});

	//申请新产品
	$(document).on("click",".main_content_middle_content_select_apply",function(){
		window.location.href=baseUrl+"userApplyInside?categoryCode=&serviceCode=";
	});

	//点击再次申请
	$(document).on("click",".main_content_middle_content_table_content_val_field_djzcsq",function(){
		var categoryCode = $(this).attr("categoryCode");
		var serverCode = $(this).attr("serviceCode");
		window.location.href=baseUrl+"userApplyInside?categoryCode="+categoryCode+"&serviceCode="+serverCode;
	});

	//接口
	$(document).on("click",".fa-info-circle",function(){
		var serverCode = $(this).attr("serviceCode");
		//window.top.location.href=baseUrl+"apidetail?serviceCode="+serverCode;
	});

	//测试
	$(document).on("click",".fa-cogs",function(){
		var serverCode = $(this).attr("serviceCode");
		//window.top.location.href=baseUrl+"apiTest?serviceCode="+serverCode;
	});

	//认证状态转换
		function stateTransformation(state){
			if(state==""||state==null){
				return false;
			}else{
				var text = "";
				if(state=="1"){
					text = "待审核";
				}
				if(state=="2"){
					text = "已通过";
				}
				if(state=="3"){
					text = "未通过";
				}
				return text;
			}
	}

	//根据状态分配不同的显示颜色
	function readColorState(state){
		if(state==""||state==null){
			return false;
		}else{
			var text = "";
			if(state=="1"){
				text = "statr_yellow";
			}
			if(state=="2"){
				text = "statr_green";
			}
			if(state=="3"){
				text = "statr_red";
			}
			return text;
		}
	}

	//字体长度判断
	function isLengs(str){
		if(str.length>8){
			str = str.substring(0,8)+"..."
		}
		return str;
	}
